import java.math.BigInteger;
import java.util.Scanner;

public class C_1444 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),m = sc.nextInt();
        BigInteger p = new BigInteger(sc.next());
//        if (n==0||m==0||p==0){
//            System.out.println(0);
//            return;
//        }
        BigInteger b;
        BigInteger t1 = new BigInteger("1");
        BigInteger t2 = new BigInteger("1");
        BigInteger nn = new BigInteger("0");
        BigInteger temp;
        if (n<=2)
            nn = BigInteger.valueOf(n);
        else
            for (int i = 3; i <= n; i++) {
                b = t1.add(t2);
                nn = nn.add(b);
                temp = t2.max(t1);
                t1 = new BigInteger(String.valueOf(temp));
                t2 = new BigInteger(String.valueOf(b));
            }
        b = new BigInteger("0");
        t1 = new BigInteger("1");
        t2 = new BigInteger("1");
        if (m<=2)
            b = new BigInteger("1");
        else
            for (int i = 3; i <= m; i++) {
                b = t1.add(t2);
                temp = t2.max(t1);
                t1 = new BigInteger(String.valueOf(temp));
                t2 = new BigInteger(String.valueOf(b));
            }
        BigInteger mm = new BigInteger(String.valueOf(b));
            nn = nn.mod(mm).mod(p);
        System.out.println(nn);
    }
}
